﻿using System;
using System.Data.Common;
using System.Web;
/// <summary>
/// Summary description for SessionManager
/// </summary>

namespace ECommerce.Library.Web
{
    /// <summary>
    /// Site Session value handler class, should be use to access session to avoid direct access errors
    /// </summary>
    public class SessionManager
    {
        #region Old Code
        //public static DbCommand Command
        //{
        //    get { return (DbCommand)System.Web.HttpContext.Current.Session["Command"]; }
        //    set { System.Web.HttpContext.Current.Session["Command"] = value; }
        //}

        //public static bool TransactionStarted
        //{
        //    get 
        //    {
        //        if (System.Web.HttpContext.Current.Session["TransactionStarted"] == null)
        //            return false;
        //        else
        //            return (bool)System.Web.HttpContext.Current.Session["TransactionStarted"];
        //    }
        //    set { System.Web.HttpContext.Current.Session["TransactionStarted"] = value; }
        //}
        #endregion

        // Property representing Logged in user of the site
        public static SiteUser LoggedUser
        {
            get { return (SiteUser)System.Web.HttpContext.Current.Session[SITE_USER]; }
            set { System.Web.HttpContext.Current.Session[SITE_USER] = value; }
        }

        // Read Only property, returns whether the user has logged-in  in the site
        public static bool IsUserLoggedIn
        {
            get { return (System.Web.HttpContext.Current.Session[SITE_USER] != null); }
        }

        // Property representing Logged in admin of the site
        public static SiteUser LoggedAdminUser
        {
            get { return (SiteUser)System.Web.HttpContext.Current.Session[SITE_ADMIN_USER]; }
            set { System.Web.HttpContext.Current.Session[SITE_ADMIN_USER] = value; }
        }

        // Read Only property, returns whether the admin has logged-in  in the site
        public static bool IsAdminUserLoggedIn
        {
            get { return (System.Web.HttpContext.Current.Session[SITE_ADMIN_USER] != null); }
        }

        // Property used for returning to a page requested before authentication
        // when authentication is complete
        public static string ReturnUrl
        {
            get { return (string)System.Web.HttpContext.Current.Session[RETURN_URL]; }
            set { System.Web.HttpContext.Current.Session[RETURN_URL] = value; }
        }

     
        // Constructors
        public SessionManager() { }

        private const string RETURN_URL = "ReturnUrl";
        private const string CURRENT_ADMIN_USER = "CurrentAdminUser";
        private const string CURRENT_USER = "CurrentUser";
        private const string SITE_ADMIN_USER = "SiteAdminUser";
        private const string SITE_USER = "SiteUser";

    }
}
